class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
}

class Solution1 {
    public TreeNode pruneTree(TreeNode root) {
        if(root == null) return null;
        if(check(root)) return null;
        root.left = pruneTree(root.left);
        root.right = pruneTree(root.right);
        return root;
    }
    public boolean check(TreeNode root) {
        if(root == null) return true;
        if(root.val == 1) return false;
        return check(root.left) && check(root.right);
    }
}

class Solution2 {
    public TreeNode pruneTree(TreeNode root) {
        if(root == null) return null;
        root.left = pruneTree(root.left);
        root.right = pruneTree(root.right);
        if(root.left == null && root.right == null && root.val == 0) {
            root = null;
        }
        return root;
    }
}

class Solution {
    int prev = Integer.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        if(root == null) return true;
        boolean tmp1 = isValidBST(root.left);
        if(tmp1==false) return false;

        if(root.val > prev) return false;
        prev = root.val;

        tmp1 = isValidBST(root.right);
        if(tmp1==false) return false;

        return true;
    }
}










public class Test {
}
